package downstream

import (
	"context"
	"mall/api/bilinadmin"
	"mall/api/inventory"
	"mall/api/member"
	"mall/api/open"
	"mall/api/pay"
	"mall/api/prod"
	"mall/api/promotion"
	"mall/internal/conf"
)

type Downstream struct {
	// 下游系统
	adminClient      bilinadmin.BilinAdminClient
	employeeClient   bilinadmin.BilinEmployeeClient
	permissionClient bilinadmin.BilinPermissionClient
	payClient        pay.PayClient
	inventoryClient  inventory.InventoryClient
	memberClient     member.MemberClient
	prodClient       prod.ProdClient
	openClient       open.OpenServiceClient
	promotionClient  promotion.OffOpServiceClient
}

func New(ctx context.Context, config *conf.Downstream) (downstream *Downstream) {
	downstream = &Downstream{}
	// 尝试建立连接，但无需依赖启动
	downstream.adminClient, _ = newAdminClient(ctx, config.AdminAddress)
	downstream.employeeClient, _ = newEmployeeClient(ctx, config.AdminAddress)
	downstream.permissionClient, _ = newPermissionClient(ctx, config.AdminAddress)
	downstream.memberClient, _ = newMemberClient(ctx, config.MemberAddress)
	downstream.payClient, _ = newPayClient(ctx, config.PayAddress)
	downstream.prodClient, _ = newProdClient(ctx, config.ProdAddress)
	downstream.promotionClient, _ = newPromotionClient(ctx, config.PromotionAddress)
	downstream.inventoryClient, _ = newInventoryClient(ctx, config.InventoryAddress)
	downstream.openClient, _ = newOpenClient(ctx, config.OpenAddress)
	return
}
